package fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.Image;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.ci_edit.R;

import activity.LoginActivity;
import activity.WelcomeActivity;
import entity.UserConfig;
import wiget.InputDialog;


/**
 * Created by hello world on 2017/7/21.
 */

public class WodeFragment extends Fragment {
    private LinearLayout mChangeQianming;
    private LinearLayout mZhuxiao;
    private LinearLayout mWodebiji;
    private LinearLayout mGengduo;
    private LinearLayout mYijian;
    private LinearLayout mGuanyu;


    private TextView mTextviewName;
    private TextView mTextviewQianming;
    private Button btnInput;

    private ImageView mImageView_head;


    @Override
    public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view = inflater.inflate(R.layout.testwode, container, false);
        mTextviewQianming = (TextView) view.findViewById(R.id.textview_Qianming);
        mTextviewName = (TextView) view.findViewById(R.id.fragmnet_my_name);
        mTextviewName.setText(UserConfig.getUsername());

        //设置透明度
        mImageView_head=(ImageView)view.findViewById(R.id.fragment_my_head);
        mImageView_head.setAlpha(200);

        //1.更改签名的点击事件
        mChangeQianming = (LinearLayout) view.findViewById(R.id.LinearLayoutChangeQianmin);
        mChangeQianming.getBackground().setAlpha(100);
        mChangeQianming.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //在这里写，更改签名的操作
                InputDialog dialog = new InputDialog(getActivity(), new InputDialog.OnEditInputFinishedListener() {

                    @Override
                    public void editInputFinished(String password) {
                        mTextviewQianming.setText(password);
                    }
                });
                dialog.setView(new EditText(getActivity()));  //若对话框无法弹出输入法，加上这句话
                dialog.show();

            }
        });

        //2.注销用户的点击事件
        mZhuxiao = (LinearLayout) view.findViewById(R.id.LinearLayoutZhuxiao);
        mZhuxiao.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //在这里写，把现有用户注销掉的代码
                if (UserConfig.getIsLogin()) {
                    UserConfig.setUsername("游客");
                    UserConfig.setIslogin(false);
                    Intent intent = new Intent();
                    intent.putExtra("zhuxiao", true);
                    intent.setClass(getContext(), LoginActivity.class);
                    startActivity(intent);

                    Toast.makeText(getActivity(), "已经注销了", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity(), "请登录", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent();
                    intent.setClass(getContext(), LoginActivity.class);
                    startActivity(intent);
                }
            }
        });

        //3.我的笔记的点击事件
        mWodebiji = (LinearLayout) view.findViewById(R.id.LinearLayoutWodebiji);
        mWodebiji.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //在这里写，点击我的笔记后发生什么
                Intent intent = new Intent();
                intent.setClass(getActivity(), activity.MyWorkActivity.class);

                startActivity(intent);
                //Toast.makeText(getActivity(),"我的笔记...", Toast.LENGTH_SHORT).show();
            }
        });

        //4.更多功能的点击事件
        mGengduo = (LinearLayout) view.findViewById(R.id.LinearLayoutGengduo);
        mGengduo.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //在这里写，点击更多功能后发什么了什么
                Toast.makeText(getActivity(), "更多功能等你探索", Toast.LENGTH_SHORT).show();
            }
        });

        //5.意见反馈的点击事件
        mYijian = (LinearLayout) view.findViewById(R.id.LinearLayoutYijian);
        mYijian.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //在这里写，点击意见反馈后发生什么
                Intent intent = new Intent();
                intent.setClass(getActivity(), activity.FeedbackActivity.class);
                startActivity(intent);
                Toast.makeText(getActivity(), "意见反馈", Toast.LENGTH_SHORT).show();
            }
        });

        //6.关于的点击事件
        mGuanyu = (LinearLayout) view.findViewById(R.id.LinearLayoutGuanyu);
        mGuanyu.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //在这里写，点击关于...后发生什么
                Toast.makeText(getActivity(), "关于...", Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }


}

